//
//  EmailCertifyViewController.m
//  bitcoin
//
//  Created by caiyajun on 2018/5/9.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "EmailCertifyViewController.h"
#import "LoginSafeTableViewController.h"

@interface EmailCertifyViewController ()
@property (weak, nonatomic) IBOutlet UIButton *changeCertifyBtn;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@end

@implementation EmailCertifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeIsEmailAction:) name:@"changeIsEmailStatue" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeEmailSafeAction:) name:@"closeEmailSafeNoti" object:nil];
    
    
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrowleft-icon"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction:)];
    self.navigationItem.leftBarButtonItem = back;
    
    
    [self.changeCertifyBtn setImage:[UIImage imageNamed:@"btmactive-icon"] forState:UIControlStateNormal];
    [self.changeCertifyBtn setImage:[UIImage imageNamed:@"btm-icon"] forState:UIControlStateSelected];
    
    if ([[UserDefaults objectForKey:K_ISEMAIL] isEqualToString:@"1"]) {
        self.emailLabel.text=[NSString stringWithFormat:@"%@",[UserDefaults objectForKey:K_EMAIL]];
        self.changeCertifyBtn.selected=YES;
    }else{
        self.emailLabel.text=@"未开启";
        self.changeCertifyBtn.selected=NO;
    }
    
}
- (void) changeIsEmailAction:(NSNotification *)notification{
    self.emailLabel.text=[NSString stringWithFormat:@"%@",[UserDefaults objectForKey:K_EMAIL]];
    self.changeCertifyBtn.selected=YES;
    
    
}
- (void) closeEmailSafeAction:(NSNotification *)notification{
    self.emailLabel.text=@"未开启";
    self.changeCertifyBtn.selected=NO;
    
    
}
- (void)backAction:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;
}

- (IBAction)changAction:(UIButton *)sender {
//    sender.selected=!sender.selected;
    if (!self.changeCertifyBtn.selected) {
        [self performSegueWithIdentifier:@"emailOpenSegue" sender:nil];
    }else{
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
        LoginSafeTableViewController *loginSafeCtrl = [sb instantiateViewControllerWithIdentifier:@"LoginSafeTableViewController"];
        loginSafeCtrl.pushType=@"emailCertifyVC";
        [self.navigationController pushViewController:loginSafeCtrl animated:YES];
        
    }
    
    
    
    
    
    
    
    
    
    
}

@end
